package client;

import java.awt.BorderLayout;
import javax.swing.JOptionPane;
import java.net.MalformedURLException;
import java.rmi.*;
import java.rmi.server.*;
import server.*;
import java.awt.Frame;
import java.awt.FlowLayout;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JFormattedTextField;

import java.awt.Dialog.ModalityType;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;

public class KTV extends JDialog {

	private final JPanel contentPanel = new JPanel();
	Person p=new Person();
	/**
	 * Launch the application.
	 */
	/*public static void main(String[] args) {
		try {
			KTV dialog = new KTV(null,"KTV",true);
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}*/

	/**
	 * Create the dialog.
	 */
	public KTV(Frame hostFrame,String title,boolean dModal) throws MalformedURLException, RemoteException, NotBoundException {
		super(hostFrame,title,dModal);
		setBounds(100, 100, 450, 300);
		setModalityType(ModalityType.APPLICATION_MODAL);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		
		try{
			Configuration config=new Configuration();
			String rmiAddress=config.getRmiAddress();
			final EntertainInterface ei = (EntertainInterface) Naming.lookup(rmiAddress+"EntertainmentSettling");
			
			/*Configuration config2=new Configuration();
			String rmiAddress2=config.getRmiAddress();
			PersonInterface p = (PersonInterface) Naming.lookup(rmiAddress+"Person");*/
			
			
		JButton btnhigh = new JButton("\u75AF\u72C2HIGH\u6B4C");
		btnhigh.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				//ei.settling(, hp, hap, exp, a)
				//.settling(id, , p.getHap(id), exp, a)
				try {
					if(!ei.hpJudge(p.getPID()))
					{
						JOptionPane.showMessageDialog(null,"HP不足！"," ",JOptionPane.OK_CANCEL_OPTION);		
					}
					else if(!ei.moneyJudge(p.getPID()))
					{
						JOptionPane.showMessageDialog(null,"money不足！"," ",JOptionPane.OK_CANCEL_OPTION);
					}
					else
					{
						ei.settling(p.getPID(), 60,40,200,'-','+','-');
						JOptionPane.showMessageDialog(null,"Hp"+"-60\n"+"Hap"+"+40\n"+"money"+"-200"," ",JOptionPane.OK_CANCEL_OPTION);
					}
				} catch (RemoteException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
		btnhigh.setBounds(99, 62, 93, 23);
		contentPanel.add(btnhigh);
		
		JButton button = new JButton("\u5C0F\u8BD5\u725B\u5200");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				try {
					if(!ei.hpJudge(p.getPID()))
					{
						JOptionPane.showMessageDialog(null,"HP不足！"," ",JOptionPane.OK_CANCEL_OPTION);		
					}
					else if(!ei.moneyJudge(p.getPID()))
					{
						JOptionPane.showMessageDialog(null,"money不足！"," ",JOptionPane.OK_CANCEL_OPTION);
					}
					else
					{
						ei.settling(p.getPID(), 40,40,200,'-','+','-');
						JOptionPane.showMessageDialog(null,"Hp"+"-40\n"+"Hap"+"+40\n"+"money"+"-200"," ",JOptionPane.OK_CANCEL_OPTION);
					}
				} catch (RemoteException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

			}
		});
		button.setBounds(99, 114, 93, 23);
		contentPanel.add(button);
		
		JButton button_1 = new JButton("\u5B89\u9759\u542C\u6B4C");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					if(!ei.hpJudge(p.getPID()))
					{
						JOptionPane.showMessageDialog(null,"HP不足！"," ",JOptionPane.OK_CANCEL_OPTION);		
					}
					else if(!ei.moneyJudge(p.getPID()))
					{
						JOptionPane.showMessageDialog(null,"money不足！"," ",JOptionPane.OK_CANCEL_OPTION);
					}
					else
					{
						ei.settling(p.getPID(), 20,60,200,'+','+','-');
						JOptionPane.showMessageDialog(null,"Hp"+"+20\n"+"Hap"+"+60\n"+"money"+"-200"," ",JOptionPane.OK_CANCEL_OPTION);
					}
				} catch (RemoteException e2) {
					// TODO Auto-generated catch block
					e2.printStackTrace();
				}

			}
		});
		button_1.setBounds(243, 114, 93, 23);
		contentPanel.add(button_1);
		
		JButton button_2 = new JButton("\u679C\u76D8\u70B9\u5FC3");
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					if(!ei.hpJudge(p.getPID()))
					{
						JOptionPane.showMessageDialog(null,"HP不足！"," ",JOptionPane.OK_CANCEL_OPTION);		
					}
					else if(!ei.moneyJudge(p.getPID()))
					{
						JOptionPane.showMessageDialog(null,"money不足！"," ",JOptionPane.OK_CANCEL_OPTION);
					}
					else
					{
						ei.settling(p.getPID(), 10,60,100,'+','+','-');
						JOptionPane.showMessageDialog(null,"Hp"+"+10\n"+"Hap"+"+60\n"+"money"+"-100"," ",JOptionPane.OK_CANCEL_OPTION);
					}
				} catch (RemoteException e3) {
					// TODO Auto-generated catch block
					e3.printStackTrace();
				}

			}
		});
		button_2.setBounds(243, 62, 93, 23);
		contentPanel.add(button_2);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						dispose();
					}
				});
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						dispose();
					}
				});
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
	  }catch(Exception e1)
	  {
			e1.printStackTrace();
	  }

		JLabel lblNewLabel = new JLabel(new ImageIcon("src/client/images/ktv.jpg"));
		lblNewLabel.setBounds(0, 0, 434, 268);
		contentPanel.add(lblNewLabel);

	}
	
}
